package main

import (
	"fmt"
	"io"
	"log"
	"net"
	"net/http"
	_ "net/http/pprof"
	"os"
)

func main() {


	http.HandleFunc("/", rootHandler)
	err := http.ListenAndServe(":80", nil)
	mux := http.NewServeMux()
	mux.HandleFunc("/healthz", healthz)
	mux.HandleFunc("/", rootHandler)

	if err != nil {
		log.Fatal(err)
	}

}

func healthz(w http.ResponseWriter, r *http.Request) {
	io.WriteString(w, "200\n")
}

func rootHandler(w http.ResponseWriter, r *http.Request) {
	os.Setenv("VERSION","1.0.0")
	version := os.Getenv("VERSION")
	fmt.Println("entering root handler")
	io.WriteString(w, "===================Details of the http request header:============\n")
	for k, v := range r.Header {
		io.WriteString(w, fmt.Sprintf("%s=%s\n", k, v))
	}
	io.WriteString(w,fmt.Sprintf("Version=%s",version))

	ip, port, err := net.SplitHostPort(r.RemoteAddr)
	fmt.Println(err)
	if err == nil {
		fmt.Printf("ip:%s,port:%s\n",ip,port)
	}
}
